package com.ruoyi.flow.listeners;

import com.ruoyi.flow.flow.workflow.FlowService;
import com.google.common.collect.Lists;
import org.activiti.bpmn.model.FlowNode;
import org.activiti.bpmn.model.MultiInstanceLoopCharacteristics;
import org.activiti.bpmn.model.Task;
import org.activiti.engine.delegate.DelegateExecution;
import org.activiti.engine.delegate.ExecutionListener;

import java.util.List;

/**
 * 财务会签执行监听器
 *
 * @author wtian
 * @version 1.0
 * @since 2018/9/7 8:37
 */
public class ExpenseCounterSignListener implements ExecutionListener {
    @Override
    public void notify(DelegateExecution execution) {
        //获取会签多实例变量
        String activitiId = execution.getCurrentActivityId();
        String definitionId = execution.getProcessDefinitionId();
        FlowNode flowNode = FlowService.activityService().getFlowNode(definitionId, activitiId);
        if (flowNode != null && flowNode instanceof Task) {
            Task task = (Task) flowNode;
            MultiInstanceLoopCharacteristics characteristics = task.getLoopCharacteristics();
            String varName = characteristics.getInputDataItem();
            List<String> signers = Lists.newArrayList();
            signers.add("test1");
            signers.add("test2");
            execution.setVariable(varName, signers);
        }
    }
}
